/**
 * Created by lwy on 2017/5/24.
 */

var shopId = GetQueryString('shopId');//获取商家id
var lnt;
var shopPhone;
var shopAddress;
var shopName;
$(function(){
    doAjax();//加载商户详情
})

function doAjax(){
    $.ajax({
        url:'/shopC/ShopDetailed.json',
        dataType:'json',
        type:'post',
        data:{
            shopId:shopId,
        },
        success:function(data){
            if(data.code==1){
                var data = data.datas;
                $('#MainImg').attr('src',data.MainImg);
                $('.shop-detail-title').html(data.ShopName);
                $('.address').html(data.ShopAddress);
                $('.shop-phone').attr('href','tel:'+data.Phone);
                $('.phone').html(data.Phone+" （"+data.RealName+"）");
                $('.shop_detail_img').empty();
                $('.mui-spinner').hide();
                $('.spinner-box').hide();
                $('#MainImg').show();
                lnt = data.address;
                shopPhone = data.Phone;
                shopAddress = data.ShopAddress;
                shopName = data.ShopName;

                    $(data.Detail).appendTo($('.shop_detail_img'));

            }
        }
    })
}


//回到顶部
$(function(){
    //当滚动条的位置处于距顶部100像素以下时，跳转链接出现，否则消失
    $(function () {
        $(window).scroll(function(){
            if ($(window).scrollTop()>300){
                $(".go-top").fadeIn(1000);
            }
            else
            {
                $(".go-top").fadeOut(1000);
            }
        });

        //当点击跳转链接后，回到页面顶部位置
        $(".go-top").click(function(){
            if ($('html').scrollTop()) {
                $('html').animate({ scrollTop: 0 }, 500);
                return false;
            }
            $('body').animate({ scrollTop: 0 }, 500);
            return false;
        });
    });
});

//调用百度地图
$('#address').click(function(){
    var url = encodeURI("map.html?shopName="+shopName+"&shopAddress="+shopAddress+"&shopPhone="+shopPhone+"&lnt="+lnt);
    window.open(url,"_self");
})

//
$(function(){
    //var rowNum=Math.round($("#address").height()/parseFloat($("#address").css('line-height')));
    //console.log($("#address").height())
    $(document).ready(function(){
        $("#MainImg").on("load",function(){
            var h = $('#address').outerHeight(true);
            if(h>52){
                $('.address').css({'line-height':'28px','margin-top':'10px','margin-bottom':'2px'})
            }
            console.log(h);
        });
    });
})